package cn.easybuy.web.backend;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.easybuy.entity.Product;
import cn.easybuy.service.ProductService;
import cn.easybuy.service.impl.ProductServiceImpl;

public class ProductSaveServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String id=request.getParameter("id");
		String level1id=request.getParameter("level1id");
		String level2id=request.getParameter("level2id");
		String level3id=request.getParameter("level3id");
		String name=request.getParameter("name");
		String price=request.getParameter("price");
		String stock=request.getParameter("stock");
		String description=request.getParameter("description");
		ProductService ps=new ProductServiceImpl();
		Product product=new Product();
		product.setId(Integer.parseInt(id));
		product.setName(name);
		product.setDescription(description);
		product.setPrice(Double.parseDouble(price));
		product.setStock(Integer.parseInt(stock));
		product.setCategoryLevel1Id(Integer.parseInt(level1id));
		product.setCategoryLevel2Id(Integer.parseInt(level2id));
		product.setCategoryLevel3Id(Integer.parseInt(level3id));
		int num=ps.update(product);
		if (num>0) {
			PrintWriter out=response.getWriter();
			out.print("success");
			out.flush();
			out.close();
					
		}
		
		
		
	}

}
